<template>
  <div class="dialpad-view">
    
    <div class="dialpad-view-header">
      <el-input 
        v-model="value" 
        :class="inputClassNames"
        @keyup.enter.native="handlerCall"
        placeholder="输入号码，按回车进行拨打" 
        clearable
      >
        <i slot="prefix" class="iconfont icon-dianhua3"></i>
      </el-input>
    </div>
    
    <div class="dialpad-view-content">
      
      <div class="dialpad-view-content-row">
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['1'])">
          {{ phoneMap['1'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['2'])">
          {{ phoneMap['2'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['3'])">
          {{ phoneMap['3'] }}
        </div>
      </div>
      
      <div class="dialpad-view-content-row">
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['4'])">
          {{ phoneMap['4'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['5'])">
          {{ phoneMap['5'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['6'])">
          {{ phoneMap['6'] }}
        </div>
      </div>
      
      <div class="dialpad-view-content-row">
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['7'])">
          {{ phoneMap['7'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['8'])">
          {{ phoneMap['8'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['9'])">
          {{ phoneMap['9'] }}
        </div>
      </div>
      
      <div class="dialpad-view-content-row">
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['*'])">
          {{ phoneMap['*'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['0'])">
          {{ phoneMap['0'] }}
        </div>
        <div class="dialpad-view-content-item" @click="addPhoneNumber(phoneMap['#'])">
          {{ phoneMap['#'] }}
        </div>
      </div>
      
    </div>
    
    <div class="dialpad-view-footer">
      <div class="dialpad-view-footer-content" @click="handlerCall">
        <i class="iconfont icon-dianhua3"></i>
      </div>
    </div>
    
  </div>
</template>

<script>
/* util */
import CallCenterZhiChiUtil from '@src/util/callcenter/CallcenterZhiChi.ts'

export default {
  name: 'dialpad',
  data() {
    return {
      value: '',
      phoneMap: {
        '1': '1',
        '2': '2',
        '3': '3',
        '4': '4',
        '5': '5',
        '6': '6',
        '7': '7',
        '8': '8',
        '9': '9',
        '0': '0',
        '*': '*',
        '#': '#',
      }
    }
  },
  computed: {
    inputClassNames() {
      return {
        'dialpad-input-large-text': this.value
      }
    }
  },
  mounted() {
    // 
  },
  methods: {
    /** 
     * @description 添加电话号码
    */
    addPhoneNumber(number) {
      this.value += number;
    },
    /**
     * @description 拨打电话
    */
    handlerCall() {
      CallCenterZhiChiUtil.agentCallOut(this.value);
      this.$emit('call', this.value);
    }
  }
}
</script>

<style lang="scss" scoped>
.dialpad-view {
  background-color: #fff;
  width: 262px;
  margin: 0 auto;
  padding: 20px;
}

.dialpad-view-header {
  ::v-deep .el-input__prefix {
    display: flex;
    align-items: center;
  }
}

.dialpad-input-large-text {
  font-size: 20px;
}

.dialpad-view-header {
  margin-bottom: 10px;
}

.dialpad-view-content-row {
  display: flex;
  flex-wrap: nowrap;
}

.dialpad-view-content-item {
  
  cursor: pointer;
  display: block;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  line-height: 48px;
  text-align: center;
  margin: 0 8px 10px;
  font-size: 20px;
  color: #3D4966;
  transition: all .3s;
  user-select:none;
  
  &:hover {
    background-color: #F5F8FF;
  }
}

.dialpad-view-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  
  .dialpad-view-footer-content {
    cursor: pointer;
    border-radius: 50%;
    background-color: $color-primary;
    display: block;
    margin: 0 auto;
    width: 50px;
    height: 50px;
    
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    
    &:hover {
      background-color: $input-border-hover-color;
    }
    
    i {
      font-size: 22px;
    }
  }
}
</style>